package com.service.impl;

import com.alibaba.fastjson.JSON;
import com.entity.PersonnelTransfer;
import com.mapper.PersonnelTransferMapper;
import com.service.PersonnelTransferService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.service.sys.UserVoService;
import com.vo.sys.UserVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author clay
 * @since 2022-04-05
 */
@Service
public class PersonnelTransferServiceImpl extends ServiceImpl<PersonnelTransferMapper, PersonnelTransfer> implements PersonnelTransferService {

    @Resource
    private UserVoService userVoService;

    /**
     * 如果状态未批核，则需要修改对应的人员的部门信息
     * @param personnelTransfer
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateByPrimary(PersonnelTransfer personnelTransfer) {
        if ("1".equals(personnelTransfer.getStatu())) {
            UserVo userVo = userVoService.getById(personnelTransfer.getUserId());
            userVo.setDepartmentId(personnelTransfer.getAfterDepartment());
            userVoService.updateById(userVo);
        }
        return this.updateById(personnelTransfer);
    }
}
